/**
 * Created by apple on 2017/6/29.
 */
export var FLAG_LANGUAGE = {flag_language:"flag_language_language",flag_key:'flag_language_key'};
import keys from '../../../res/data/keys.json'
import React,{Component} from 'react';
import {
  AsyncStorage,
} from "react-native";
export default class LanguageDao {
  constructor(flag) {
    this.flag = flag;
  }
  save(data){
    AsyncStorage.setItem(this.flag,JSON.stringify(data),(err)=>{

    })
  }
  fetch() {
    return new Promise((resolve, reject) => {
      AsyncStorage.getItem(this.flag,(err,result) =>{
        if(err){
          reject(err)
        }else{
          if(result){
            try{
            resolve(JSON.parse(result))
            }catch(e){
              reject(e)
            }
          }else{
            let data= this.flag===FLAG_LANGUAGE.flag_key?keys:null;
            this.save(data)
            resolve(data)
          }
        }
      })
    })

  }
}